package reliability.ui;

import javax.swing.*;
import java.awt.*;

public class NodeLabel
    extends JPanel
{
    boolean isSelected = false;

    public static final int SIZE = 23;
    private Integer key;

    public NodeLabel(Integer key)
    {
        super();
        this.key = key;
        setPreferredSize(new Dimension(SIZE, SIZE));
        setBackground(new Color(0, 0, 0, 0));
        setLayout(null);
        JLabel textLabel = new JLabel();
        textLabel.setBounds(0, 0, SIZE, SIZE);
        textLabel.setHorizontalAlignment(SwingConstants.CENTER);
        textLabel.setText(key.toString());
        add(textLabel);
    }

    public void setSelected(boolean isSelected)
    {
        this.isSelected = isSelected;
    }

    public Integer getKey()
    {
        return key;
    }

    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(new Color(255, 34, 0));
        g.fillOval(0, 0, SIZE, SIZE);
        Color fillColor = (isSelected)
                ? new Color(0, 196, 79)
                : new Color(204, 204, 255);
        g.setColor(fillColor);
        g.fillOval(1, 1, SIZE - 2, SIZE - 2);
    }
}
